var sortColors = function(arr) {
    let twoPos = arr.length - 1
    for (let i = 0; i < arr.length; i++) {
        const item = arr[i];
        if (item === 2) {
            let tempItem = arr[twoPos]
            while (tempItem === 2 && twoPos >= i) {
                twoPos--
                tempItem = arr[twoPos]
            }
            if (twoPos <= i) break
            let temp = arr[twoPos]
            arr[twoPos] = arr[i]
            arr[i] = temp
            twoPos--
        }
    }
    console.log(arr)
    let onePos = twoPos
    for (let i = 0; i < twoPos + 1; i++) {
        const item = arr[i];
        if (item === 1) {
            let tempItem = arr[onePos]
            while (tempItem === 1 && onePos >= i) {
                onePos--
                tempItem = arr[onePos]
            }
            if (onePos <= i) break
            let temp = arr[onePos]
            arr[onePos] = arr[i]
            arr[i] = temp
        }
    }
    return arr
};
console.log(sortColors([1, 2]))